﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.ModelConfiguration;
using PraiseSystem.Domain.Entities;
using System.ComponentModel.DataAnnotations.Schema;

namespace PraiseSystem.Domain.Concreate
{
    public class EntitiesConfiguration
    {
        public class PraiseMap : EntityTypeConfiguration<Praise>
        {
            public PraiseMap()
            {
                ToTable("tb_Praise");
                HasKey(p => p.PraiseID);
                Property(p => p.PraiseDate).IsRequired();
                Property(p => p.DeleteFlag).IsRequired();
                Property(p => p.PraiseID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            }
        }

        public class ReceiverMap : EntityTypeConfiguration<Receiver>
        {
            public ReceiverMap()
            {
                ToTable("tb_Receiver");
                HasKey(r => r.ReceiverID);
                Property(p => p.Name).IsRequired().HasMaxLength(10);
                HasMany(u => u.ReceivedPraises).WithMany(p => p.Receivers).Map(m => m.ToTable("User_Praise_Mapping"));
            }
        }

        public class UserMap : EntityTypeConfiguration<User>
        {
            public UserMap()
            {
                ToTable("tb_User");
                HasKey(u => u.UserID);
                Property(p => p.UserID).HasMaxLength(10);
                Property(p => p.Name).IsRequired().HasMaxLength(10);
                HasMany(u => u.Praises).WithRequired(p => p.Owner).HasForeignKey(p => p.OwnerID);
            }
        }
    }
}
